 <script type="text/javascript">
    $(function () {
        $('[data-toggle="tooltip"]').tooltip();
        $('#showbindlink').on('show.bs.modal', function (event) {
          var button = $(event.relatedTarget);
          var recipient = button.data('whatever');
          var modal = $(this);
          //modal.find('.modal-title').text('New message to ' + recipient)
          modal.find('.modal-body input').val("https://open.weixin.qq.com/connect/oauth2/authorize?appid={$Think.config.WX_APPID}&redirect_uri={$Think.config.WX_BACK_URL|urlencode}&response_type=code&scope=snsapi_userinfo&state="+recipient+"#wechat_redirect");
        });

        $("#importuser").bind("click",function(){
          $("#fileToUpload").click();
        });
    })

        function fileSelected(fileToUpload) {
            var file = document.getElementById(fileToUpload).files[0];
            if (file) {
                $(".progress").show();
                var fd = new FormData();
                fd.append("fileToUpload", document.getElementById(fileToUpload).files[0]);
                var xhr = new XMLHttpRequest();
                xhr.upload.addEventListener("progress", uploadProgress, false);
                xhr.addEventListener("load", uploadComplete, false);
                xhr.addEventListener("error", uploadFailed, false);
                xhr.addEventListener("abort", uploadCanceled, false);
                xhr.open("POST", "__APP__/User/importuser");//修改成自己的接口
                xhr.send(fd);
            }
        }

        function uploadProgress(evt) {
            if (evt.lengthComputable) {
                var percentComplete = Math.round(evt.loaded * 100 / evt.total);
                //document.getElementById('progressNumber').innerHTML = percentComplete.toString() + '%';
                $(".progress-bar").css("width",function(){return percentComplete.toString() + '%'});
                $(".progress-bar").text(percentComplete.toString() + '%');
            }else {
                document.getElementById('progressNumber').innerHTML = 'unable to compute';
            }
        }
            
        function uploadComplete(evt) {
            /* 服务器端返回响应时候触发event事件*/
            //alert(evt.target.responseText);
            var res= JSON.parse(evt.target.responseText);
            if(res.status==1){
                alert('导入成功');
                $(".progress").hide();
                var file = $("#fileToUpload") 
                file.after(file.clone().val("")); 
                file.remove();
                gourl('__APP__/User/index/bind/1');
            }else{
                alert(res.msg);
                var file = $("#fileToUpload") 
                file.after(file.clone().val("")); 
                file.remove();
            }
        }
        function uploadFailed(evt) {
            alert("There was an error attempting to upload the file.");
        }
        function uploadCanceled(evt) {
            alert("The upload has been canceled by the user or the browser dropped the connection.");
        }
 </script>

 <div class="row">
                <div class="col-lg-12" style="padding:15px;">
                        <div >                         
                            <input type="text"  style="width:30%;float:left" name="key" class="form-control" placeholder="搜索用户">
                            <button type="button" class="btn btn-info" style="float:left" onclick="searchkey();">
                                <i class="fa fa-search"></i>
                            </button>   
                        </div>
                        <script type="text/javascript">
                            function searchkey(){
                                var key = $("input[name='key']").val();
                                if(!key){
                                    return;
                                }else{
                                    gourl('__APP__/User/search/key/'+key);
                                }
                            }
                        </script>            
                </div>
                <!-- /.col-lg-12 -->
            </div>
            <!-- /.row -->
            <div class="row">
                <div class="col-lg-12">
                    <div class="panel panel-default">
                        <div class="panel-heading">
                            <button type="button" class="btn btn-success btn-xs" onclick="editurl('__APP__/User/add/page/{$currentpage}');">添加用户</button> 
                            <button type="button" class="btn btn-success btn-xs" id="importuser">导入用户</button>
                            <div class="progress" style="display:none;width:200px;margin-top:12px;">
                                <div class="progress-bar" role="progressbar" aria-valuenow="60" aria-valuemin="0" aria-valuemax="100" style="width: 60%;">
                                    60%
                                </div>
                            </div>
                            <input type="file" name="fileToUpload" accept=".csv" id="fileToUpload" onchange="fileSelected('fileToUpload');" style="display:none;"/>
                            <div class="dropdown" style="float:right">
                            <button id="dLabel" class="btn btn-default btn-xs" style="margin-right:60px;" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                                用户等级筛选
                            <span class="caret"></span>
                            </button>
                            <ul class="dropdown-menu" role="menu" aria-labelledby="dLabel">
                                <li role="presentation"><a role="menuitem" tabindex="-1" style="cursor:pointer" onclick="level='0';filteruser();">所有等级</a></li> 
                                <volist name="levels" id="vo">
                                <li role="presentation"><a role="menuitem" tabindex="-1" style="cursor:pointer" onclick="level='{$vo.id}';levelname='{$vo.level}';filteruser();">{$vo.level}</a></li>
                                </volist>                                   
                            </ul>
                            </div>
                            <div class="dropdown" style="float:right">
                            <button id="dLabel2" class="btn btn-default btn-xs" style="margin-right:20px;" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                                用户地区筛选
                            <span class="caret"></span>
                            </button>
                            <ul class="dropdown-menu" style="height:300px;overflow:auto; " role="menu" aria-labelledby="dLabel2">
                                <li role="presentation"><a role="menuitem" tabindex="-1" style="cursor:pointer" onclick="province='0';filteruser();">全国</a></li> 
                                <volist name="provinces" id="vo">
                                <li role="presentation"><a role="menuitem" tabindex="-1" style="cursor:pointer" onclick="province='{$vo.name}';filteruser();">{$vo.name}</a></li>
                                </volist>                                   
                            </ul>
                            </div>
                            <div class="dropdown" style="float:right">
                            <button id="dLabel3" class="btn btn-default btn-xs" style="margin-right:20px;" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                                用户绑定筛选
                            <span class="caret"></span>
                            </button>
                            <ul class="dropdown-menu" role="menu" aria-labelledby="dLabel3">
                                <li role="presentation"><a role="menuitem" tabindex="-1" style="cursor:pointer" onclick="bind='0';filteruser();">所有用户</a></li> 
                                <li role="presentation"><a role="menuitem" tabindex="-1" style="cursor:pointer" onclick="bind='1';filteruser();">待绑定用户</a></li>
                                <li role="presentation"><a role="menuitem" tabindex="-1" style="cursor:pointer" onclick="bind='2';filteruser();">已绑定用户</a></li>
                            </ul>
                            </div>
                            <div class="dropdown" style="float:right">
                            <button id="dLabel4" class="btn btn-default btn-xs" style="margin-right:20px;" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                                账号状态
                            <span class="caret"></span>
                            </button>
                            <ul class="dropdown-menu" role="menu" aria-labelledby="dLabel4">
                                <li role="presentation"><a role="menuitem" tabindex="-1" style="cursor:pointer" onclick="status='0';filteruser();">所有状态</a></li> 
                                <li role="presentation"><a role="menuitem" tabindex="-1" style="cursor:pointer" onclick="status='1';filteruser();">正常状态</a></li>
                                <li role="presentation"><a role="menuitem" tabindex="-1" style="cursor:pointer" onclick="status='2';filteruser();">停用状态</a></li>
                            </ul>
                            </div>
                        </div>
                        <!-- /.panel-heading -->
                        <div class="panel-body">
                            <div class="dataTable_wrapper">
                                <table class="table table-striped table-bordered table-hover">
                                    <thead>
                                        <tr>
                                            <th><center>{:L('headimgurl')}</center></th>
                                            <th><center>{:L('nickname')}</center></th>
                                            <th><center>{:L('name')}</center></th>
                                            <th><center>{:L('mobile')}</center></th>
                                            <th><center>{:L('hospital')}</center></th>
                                            <th><center>{:L('gender')}</center></th>
                                            <th><center>{:L('level')}</center></th>
                                            <th><center>{:L('status')}</center></th>
                                            <th><center>{:L('lastlogin')}</center></th>
                                            <th><center>{:L('operation')}</center></th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <volist name="normallist" id="vo">
                                        <tr class="odd gradeX">
                                            <td><center><img src="<if condition="$vo.image eq ''">{$vo.headimgurl}<else />{$vo.image}</if>" width="50"></center></td>
                                            <td style="vertical-align: middle;">
                                                <center>
                                                    <if condition="$vo.openid eq ''">
                                                    <button type="button" class="btn btn-primary btn-xs" data-toggle="modal" data-target="#showbindlink" data-whatever="{$vo.token}">
                                                        <i class="fa fa-link"> 获取绑定链接</i>
                                                    </button>                                                    
                                                    <else />
                                                        {$vo.nickname|base64_decode}
                                                    </if>
                                                </center>
                                            </td>
                                            <td style="vertical-align: middle;">
                                                <center>
                                                    <if condition="$vo.name eq ''">
                                                        <button type="button" class="btn btn-danger btn-xs">
                                                            <i class="fa fa-minus"></i>
                                                        </button> 
                                                    <else />
                                                        {$vo.name}
                                                    </if>
                                                </center>
                                            </td>
                                            <td style="vertical-align: middle;">
                                                <center>
                                                    <if condition="$vo.mobile eq ''">
                                                        <button type="button" class="btn btn-danger btn-xs">
                                                            <i class="fa fa-minus"></i>
                                                        </button> 
                                                    <else />
                                                        {$vo.mobile}
                                                    </if>
                                                </center>
                                            </td>
                                            <td style="vertical-align: middle;">
                                                <center>
                                                    <if condition="$vo.hospital eq ''">
                                                        <button type="button" class="btn btn-danger btn-xs">
                                                            <i class="fa fa-minus"></i>
                                                        </button> 
                                                    <else />
                                                        {$vo.hospital}
                                                    </if>
                                                </center>
                                            </td>
                                            <td style="vertical-align: middle;">
                                                <center>
                                                    <if condition="$vo.sex eq 1">
                                                        男
                                                    <else />
                                                        女
                                                    </if>
                                                </center>
                                            </td>
                                            <td style="vertical-align: middle;">
                                                <center>
                                                  {$vo.levelname}
                                                </center>
                                            </td>
                                            <td style="vertical-align: middle;">
                                                <center>
                                                    <if condition="$vo.status eq 1">
                                                        <span class="label label-success">正常</span>
                                                    <else />
                                                       <span class="label label-danger">停用</span>
                                                    </if>
                                                </center>
                                            </td>
                                            <td class="center" style="vertical-align: middle;"><center>{$vo.created}</center></td>
                                            <td class="center" style="vertical-align: middle;">
                                                <center>
                                                    <button tyep="button" class="btn btn-success btn-xs" data-toggle="tooltip" data-placement="bottom" title="管理用户消费" onclick="editurl('__APP__/Cash/user/id/{$vo.id}')">
                                                        <i class="fa fa-credit-card"></i>
                                                    </button>
                                                    <button tyep="button" class="btn btn-danger btn-xs" data-toggle="tooltip" data-placement="bottom" title="管理用户金豆" onclick="editurl('__APP__/Points/user/id/{$vo.id}')">
                                                        <i class="fa fa-sun-o"></i>
                                                    </button>
                                                    <button tyep="button" class="btn btn-info btn-xs" data-toggle="tooltip" data-placement="bottom" title="管理用户活动" onclick="editurl('__APP__/Event/user/id/{$vo.id}')">
                                                        <i class="fa fa-users"></i>
                                                    </button>
                                                    <button tyep="button" class="btn btn-warning btn-xs" data-toggle="tooltip" data-placement="bottom" title="管理用户评论" onclick="editurl('__APP__/Discuss/user/id/{$vo.id}')">
                                                        <i class="fa fa-coffee"></i>
                                                    </button>
                                                    <button tyep="button" class="btn btn-danger btn-xs" data-toggle="tooltip" data-placement="bottom" title="管理用户等级并设定打包价格" onclick="editurl('__APP__/Userlevel/user/id/{$vo.id}')">
                                                        <i class="fa fa-sitemap fa-fw"></i>
                                                    </button>
                                                    <button tyep="button" class="btn btn-info btn-xs" data-toggle="tooltip" data-placement="bottom" title="管理用户病历" onclick="editurl('__APP__/Medicalrecord/user/id/{$vo.id}')">
                                                        <li class="fa fa-list-alt"></li>
                                                    </button>
                                                    <button type="button" class="btn btn-primary btn-xs" data-toggle="tooltip" data-placement="bottom" title="编辑用户资料" onclick="editurl('__APP__/User/edit/id/{$vo.id}/page/{$currentpage}/levels/{$level}/province/{$province}/bind/{$bind}/status/{$status}');">
                                                        <i class="fa fa-edit"></i>
                                                    </button>
                                                    <if condition="$vo.status eq 1">
                                                    <button type="button" class="btn btn-warning btn-xs" data-toggle="tooltip" data-placement="bottom" title="账号停用" onclick="stop({$vo.id});">
                                                        <i class="fa fa-times"></i>
                                                    </button>
                                                    <else />
                                                    <button type="button" class="btn btn-warning btn-xs" data-toggle="tooltip" data-placement="bottom" title="账号启用" onclick="play({$vo.id});">
                                                        <i class="fa fa-play"></i>
                                                    </button>
                                                    </if>
                                                </center>
                                            </td>
                                        </tr>
                                        </volist>
                                    </tbody>
                                </table>
                            </div>
                            {$page}
                        </div>
                        <!-- /.panel-body -->
                    </div>
                    <!-- /.panel -->
                </div>
                <!-- /.col-lg-12 -->
            </div>
            <!-- /.row -->
        </div>
        <div class="modal fade" id="showbindlink" tabindex="-1" role="dialog" aria-labelledby="showbindlinkLabel" aria-hidden="true">
          <div class="modal-dialog">
            <div class="modal-content">
              <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="showbindlinkLabel">获取绑定链接</h4>
              </div>
              <div class="modal-body">
                <form>
                  <div class="form-group">
                    <label for="recipient-name" class="control-label">链接地址:</label>
                    <input type="text" class="form-control" id="recipient-name">
                  </div>
                </form>
              </div>
              <div class="modal-footer">
                <button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>
              </div>
            </div>
          </div>
        </div>
    <!-- Page-Level Demo Scripts - Tables - Use for reference -->
    <script>
    var level='{$level}';
    var province='{$province}';
    var bind='{$bind}';
    var status='{$status}';

    level!=0  ? $('#dLabel').html('{$levelname}<span class="caret"></span>') : $('#dLabel').html('所有等级<span class="caret"></span>');
    province!=0  ? $('#dLabel2').html(province+'<span class="caret"></span>') : $('#dLabel2').html('全国<span class="caret"></span>');
    bind==1 &&  $('#dLabel3').html('待绑定用户<span class="caret"></span>');
    bind==2 &&  $('#dLabel3').html('已绑定用户<span class="caret"></span>');
    bind==0 &&  $('#dLabel3').html('所有用户<span class="caret"></span>');
    status==1 &&  $('#dLabel4').html('正常状态<span class="caret"></span>');
    status==2 &&  $('#dLabel4').html('停用状态<span class="caret"></span>');
    status==0 &&  $('#dLabel4').html('所有状态<span class="caret"></span>');
    function filteruser(){
        gourl('__APP__/User/index/level/'+level+'/province/'+province+'/bind/'+bind+'/status/'+status);
    }
    function stop(id){
        if(confirm('是否要停用?')){
            $.post('__APP__/User/stop',{id:id},function(data){
                if(data.status==1){
                    //alert('操作成功');
                    gourl('__APP__/User/index/p/{$currentpage}');
                }else{
                    alert('操作失败');
                }
            });
        }else{
            return;
        }
    }
    function play(id){
        if(confirm('是否要启用?')){
            $.post('__APP__/User/play',{id:id},function(data){
                if(data.status==1){
                    //alert('操作成功');
                    gourl('__APP__/User/index/p/{$currentpage}');
                }else{
                    alert('操作失败');
                }
            });
        }else{
            return;
        }
    }
    </script>

</body>

</html>
